import 'dart:core';
import 'package:Flutter_Demo/core/model/meal_model.dart';
import 'package:Flutter_Demo/core/services/json_parse.dart';
import 'package:Flutter_Demo/core/services/meal_request.dart';
import 'package:flutter/cupertino.dart';
import 'fliter_view_model.dart';

class MYMealViewModel extends ChangeNotifier {
  List<MYMealModel> _meals = [];

  MYFliterViewModel _fliterViewModel;


  void updateFliters(MYFliterViewModel fliterViewModel) {
    _fliterViewModel = fliterViewModel;
  }

  List<MYMealModel> get meals {
    return _meals.where((meal) {
      if(_fliterViewModel.isGlutenFree && !meal.isGlutenFree) return false;
      if(_fliterViewModel.isLactoseFree && !meal.isLactoseFree) return false;
      if(_fliterViewModel.isVegetarian && !meal.isVegetarian) return false;
      if(_fliterViewModel.isVegan && !meal.isVegan) return false;
      return true;
    }).toList();
  }


    List<MYMealModel> get originMeals {
    return _meals;
    }

  MYMealViewModel() {
//    MYMealRequest.getMealData().then((value){
//      _meals = value;
//      notifyListeners();
//    });

    MYJsonParse.getMealData().then((value) {
      _meals = value;
      notifyListeners();
    });
  }

}